package com.ny.zmb.glxt.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ny.zmb.glxt.entity.PmStore;
import com.ny.zmb.glxt.mapper.PmStoreMapper;
import com.ny.zmb.glxt.service.IPmStoreService;
import com.ny.zmb.openapi.controller.entity.Result;
import com.ny.zmb.openapi.entity.PmUserToken;
import com.ny.zmb.openapi.service.IPmUserTokenService;
import com.ny.zmb.openapi.ysutil.base.EYinShengBase;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 * 店铺申请表 前端控制器
 * </p>
 *
 * @author xie
 * @since 2024-10-10
 */
@RestController
@RequestMapping("/glxt/pmStore")
@CrossOrigin
public class PmStoreController extends EYinShengBase {

    @Resource
    private IPmStoreService storeService;

    @Resource
    private PmStoreMapper storeMapper;

    @RequestMapping("commitInfoToZMB")
    public Result commitInfoToZMB(@RequestBody JSONObject jsonObject) {

        PmUserToken userDetailByToken = getUserToken();
        Integer userId = userDetailByToken.getUserId();
        jsonObject.put("userId", userId);
        return storeService.commitInfoToZMB(jsonObject);
    }
    @RequestMapping("commitInfoToZMBByOutMerchantNo")
    public Result commitInfoToZMBByOutMerchantNo( @RequestBody JSONObject jsonObject) {
        PmUserToken userDetailByToken = getUserToken();
        Integer userId = userDetailByToken.getUserId();
        jsonObject.put("userId", userDetailByToken.getUserId());
        return storeService.commitInfoToZMBByOutMerchantNo(jsonObject,userId);
    }

    @RequestMapping("get")
    public Result get(@RequestBody PmStore obj) {
        List<PmStore>  list= storeService.get(obj);
        return Result.ok(list);
    }
    @RequestMapping("getList")
    public IPage<PmStore> getList(
            PmStore pmStore,
            @RequestParam(defaultValue = "1") int currentPage,
            @RequestParam(defaultValue = "10") int pageSize
    ) {
        IPage<PmStore> page = new Page<>(currentPage, pageSize);
        QueryWrapper<PmStore> pmStoreQueryWrapper = new QueryWrapper<>(pmStore);
        return storeService.page(page, pmStoreQueryWrapper);

    }


    @RequestMapping("getStoreXxxx")
    public HashMap<String, Object> getStoreXxxx(
            PmStore pmStore
    ) {
        final HashMap<String, Object> store = storeMapper.selectStore(pmStore);
        final HashMap<String, Object> ysStore = storeMapper.selectYsStore(pmStore);
        HashMap<String, Object> arrStore = new HashMap<>();
        arrStore.put("store", store);
        arrStore.put("storeYs", ysStore);
        return arrStore;

    }


}
